﻿using System.Reflection;
using CommandLine;
using CommandLine.Text;

namespace SignFiles
{
    public class Options
    {
        private readonly HeadingInfo _headingInfo;

        private static string exeName()
        {
            return Assembly.GetEntryAssembly().GetName().Name;
        }

        public Options()
        {
            _headingInfo = new HeadingInfo(string.Format("Crypton {0} - file signing utility.", exeName()), 
                "Version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
        }

        [Option("s", "source", HelpText = "Source files mask. Wildcard (* and ?) symbols usage is allowed.", Required = true)]
        public string Source = "";

        [Option("d", "dest", HelpText = "Destination directory for sing files."+
            "Default value is source files directory.")]
        public string Dest = "";

        [Option("k", "key", HelpText = "The name of private key file.", Required = true)]
        public string Key = "";

        [HelpOption(HelpText = "Dispaly this help screen.")]
        public string GetUsage()
        {
            var help = new HelpText(_headingInfo)
                           {
                               AdditionalNewLineAfterOption = false,
                               Copyright = new CopyrightInfo("Vladimir V.Boborykin", 2010, 2011)
                           };
            help.AddPreOptionsLine(@"".PadRight(70, '-'));
            help.AddPreOptionsLine(string.Format(@"USAGE: {0} -s[ource] sourceMask -k[ey] keyName [-d[est] destDir]", exeName()));

            help.AddPostOptionsLine(@"EXAMPLES:");
            help.AddPostOptionsLine(@" Sign file c:\source\data.dat with private key stored in a:\key.prikey:");
            help.AddPostOptionsLine(string.Format(@"  {0}.exe -s c:\source\data.dat -k a:\key.prikey", exeName()));

            help.AddOptions(this);

            return help;
        }
    }
}
